import os

from flask import jsonify, Blueprint, request, current_app

callback = Blueprint('callback', __name__)


@callback.route('gitee', methods=['POST'])
def gitee():
    """
    GITEE构子处理
    :return:
    """
    data = request.get_json()
    msg = "未执行脚本"
    password = current_app.config.get("GITEE_CALLBACK_PASSWORD")
    shell = current_app.config.get("GITEE_CALLBACK_SHELL")
    if data.get('password') == password and os.path.exists(shell):
        res = os.system(f"sh {shell}")
        msg = f"已执行脚本{shell}, res:{res}"
    print(msg)
    return jsonify({"object": True, "successful": True, "msg": msg})
